<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="挂号单ID" prop="postCode">
        <el-input
          v-model="queryParams.number"
          placeholder="请输入挂号单"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">读取IC卡</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange">

      <el-table-column label="挂号单号" align="center" prop="number" />
      <el-table-column label="科室名称" align="center" prop="deptName" />
      <el-table-column label="就诊时间" align="center" prop="date" />
      <el-table-column label="诊断信息" align="center" prop="diagnosis" />
      <el-table-column label="医生姓名" align="center" prop="docterName" />
      <el-table-column label="患者姓名" align="center" prop="patientName" />
      <el-table-column label="主诉" align="center" prop="discribe" />
      <el-table-column label="医生建议" align="center" prop="proposal" />
    </el-table>



    <el-collapse v-model="activeNames" @change="handleChange">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['drugs:supplier:add']"
          >全选</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['drugs:supplier:edit']"
          >取消全选</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['drugs:supplier:remove']"
          >现金</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['drugs:supplier:edit']"
          >支付宝</el-button>
        </el-col>

      </el-row>
      <el-collapse-item title="【检查处方】【1】【处方总额】:¥105" name="1">
        <div>

        </div>
      </el-collapse-item>
      <el-collapse-item title="【药品处方】【2】【处方总额】:¥16" name="2">
        <div>
          <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="序号" align="center" prop="drug.id" />
            <el-table-column label="药品名称" align="center" prop="drug.name" />
            <el-table-column label="数量" align="center" prop="orderNumber" />
            <el-table-column label="单价（元）" align="center" prop="orderPrice" />
            <el-table-column label="金额（元）" align="center" prop="orderTotal" />
            <el-table-column label="服用备注" align="center" prop="orderBath" />
            <el-table-column label="支付状态" align="center" prop="drug.producer.proname" />
          </el-table>
        </div>

      </el-collapse-item>
    </el-collapse>


    <!-- 添加或修改岗位对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="供应商名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入岗位名称" />
        </el-form-item>
        <el-form-item label="联系人" prop="boss">
          <el-input v-model="form.boss" placeholder="请输入编码名称" />
        </el-form-item>
        <el-form-item label="手机" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入编码名称" />
        </el-form-item>
        <el-form-item label="银行账号" prop="card">
          <el-input v-model="form.card" placeholder="请输入编码名称" />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入编码名称" />
        </el-form-item>
        <el-form-item label="岗位状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="  dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
    //import { listPost, getPost, delPost, addPost, updatePost, exportPost } from "@/api/system/post";
    import {listSup} from "../../../api/charge/pcharge/pcharge";



    export default {

        name: "Post",
        data() {
            return {
                // 遮罩层
                loading: false,
                activeNames: ['1'],
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 岗位表格数据
                postList: [],
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 状态数据字典
                statusOptions: [],
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    name: undefined,
                    boss: undefined,
                    phone:undefined,
                    status: undefined,
                    number:undefined,
                },
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                    name: [
                        { required: true, message: "供应商名称不能为空", trigger: "blur" }
                    ],
                    boss: [
                        { required: true, message: "联系人不能为空", trigger: "blur" }
                    ],
                    phone: [
                        { required: true, message: "手机号不能为空", trigger: "blur" }
                    ],
                    card: [
                        { required: true, message: "银行卡号不能为空", trigger: "blur" }
                    ],
                    address: [
                        { required: true, message: "地址不能为空", trigger: "blur" }
                    ]
                }
            };
        },
        created() {

            this.getDicts("sys_normal_disable").then(response => {
                this.statusOptions = response.data;
            });
        },
        methods: {
            /** 查询供应商列表 */
            getList() {
                this.loading = true;
                listSup(this.queryParams).then(response => {
                    this.postList = response.data;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            // 供应商状态字典翻译
            statusFormat(row, column) {
                return this.selectDictLabel(this.statusOptions, row.status);
            },
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                    id:undefined,
                    name: undefined,
                    boss: undefined,
                    phone: undefined,
                    card:undefined,
                    address:undefined,
                    postSort: 0,
                    status: "0",
                };
                this.resetForm("form");
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },

            handleChange(val) {
                console.log(val);
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id)
                this.single = selection.length!=1
                this.multiple = !selection.length
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();

            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids
                getSup(id).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改供应商";
                });
            },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != undefined) {
                            updateSup(this.form).then(response => {
                                this.msgSuccess("修改成功");
                                this.open = false;
                                this.getList();
                            });
                        } else {
                            addSup(this.form).then(response => {
                                this.msgSuccess("新增成功");
                                this.open = false;
                                this.getList();
                            });
                        }
                    }
                });
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const id = row.id || this.ids;
                this.$confirm('是否确认删除岗位编号为"' + id + '"的数据项?', "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(function() {
                    return delSup(id);
                }).then(() => {
                    this.getList();
                    this.msgSuccess("删除成功");
                })
            },
        }
    };
</script>
